﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;
using System.IO;

namespace RssBar.Net
{
    /// <summary>
    /// Wspomagacz ściągania internetu na dyskietki
    /// </summary>
    public static class NetHelpers
    {
        /// <summary>
        /// Funkcja pobiera sam tekst z podanego adresu
        /// </summary>
        /// <param name="address">Adres </param>
        /// <returns>Treść</returns>
        public static string DownloadString(string address)
        {
            string downloadString = String.Empty;

            Thread downloadThread = new Thread(() =>
            {
                using (var response = (HttpWebResponse)WebRequest.Create(address).GetResponse())
                {
                    using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet)))
                    {
                        downloadString = reader.ReadToEnd();
                    }
                }
            });
            downloadThread.Start();
            downloadThread.Join();

            return downloadString;
        }
    }
}
